package com.xjrsoft.module.customerTwo.AppManage.service_contract.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjrsoft.core.tool.utils.StringUtil;
import com.xjrsoft.module.customerTwo.AppManage.service_contract.entity.ServiceContract;

import com.xjrsoft.module.customerTwo.AppManage.service_contract.dto.ServiceContractListDto;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.ConventPage;

import java.util.List;
import com.xjrsoft.module.customerTwo.AppManage.service_contract.mapper.ServiceContractMapper;
import com.xjrsoft.module.customerTwo.AppManage.service_contract.service.IServiceContractService;
import com.xjrsoft.core.mp.base.BaseService;
import com.xjrsoft.core.tool.utils.Func;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;


/**
 *  服务实现类
 *
 * @author lisen
 * @since 2024-04-25
 */
@Service
@AllArgsConstructor
public class ServiceContractServiceImpl extends BaseService<ServiceContractMapper, ServiceContract> implements IServiceContractService {


	@Override
	public IPage<ServiceContract> getPageList(ServiceContractListDto pageListDto) {
		Wrapper<ServiceContract> wrapper = Wrappers.<ServiceContract>query().lambda()
				.like(!StringUtil.isEmpty(pageListDto.getOrder_id()), ServiceContract::getOrderId, pageListDto.getOrder_id())
				.like(!StringUtil.isEmpty(pageListDto.getService_number()), ServiceContract::getServiceNumber, pageListDto.getService_number())
				.like(!StringUtil.isEmpty(pageListDto.getAssembly_id()), ServiceContract::getAssemblyId, pageListDto.getAssembly_id())
				.like(!StringUtil.isEmpty(pageListDto.getCustomer_id()), ServiceContract::getCustomerId, pageListDto.getCustomer_id())
				.like(!StringUtil.isEmpty(pageListDto.getCustomer_code()), ServiceContract::getCustomerCode, pageListDto.getCustomer_code())
				.like(!StringUtil.isEmpty(pageListDto.getContactor_id()), ServiceContract::getContactorId, pageListDto.getContactor_id())
				.like(!StringUtil.isEmpty(pageListDto.getContactor_name()), ServiceContract::getContactorName, pageListDto.getContactor_name())
				.like(!StringUtil.isEmpty(pageListDto.getContactor_phone()), ServiceContract::getContactorPhone, pageListDto.getContactor_phone())
				.ge(!StringUtil.isEmpty(pageListDto.getCreate_date_Start()), ServiceContract::getCreateDate, pageListDto.getCreate_date_Start())
				.le(!StringUtil.isEmpty(pageListDto.getCreate_date_End()), ServiceContract::getCreateDate, pageListDto.getCreate_date_End())
				.eq(!StringUtil.isEmpty(pageListDto.getSales_department_id()), ServiceContract::getSalesDepartmentId, pageListDto.getSales_department_id())
				.eq(!StringUtil.isEmpty(pageListDto.getSales_man_id()), ServiceContract::getSalesManId, pageListDto.getSales_man_id())
				.like(!StringUtil.isEmpty(pageListDto.getContract_name()), ServiceContract::getContractName, pageListDto.getContract_name())
				.ge(!StringUtil.isEmpty(pageListDto.getContract_start_date_Start()), ServiceContract::getContractStartDate, pageListDto.getContract_start_date_Start())
				.le(!StringUtil.isEmpty(pageListDto.getContract_start_date_End()), ServiceContract::getContractStartDate, pageListDto.getContract_start_date_End())
				.ge(!StringUtil.isEmpty(pageListDto.getContract_end_date_Start()), ServiceContract::getContractEndDate, pageListDto.getContract_end_date_Start())
				.le(!StringUtil.isEmpty(pageListDto.getContract_end_date_End()), ServiceContract::getContractEndDate, pageListDto.getContract_end_date_End())
				.eq(!StringUtil.isEmpty(pageListDto.getTax_amount()), ServiceContract::getTaxAmount, pageListDto.getTax_amount())
				.eq(!StringUtil.isEmpty(pageListDto.getNone_tax_amount()), ServiceContract::getNoneTaxAmount, pageListDto.getNone_tax_amount())
				.like(!StringUtil.isEmpty(pageListDto.getContract_instruction()), ServiceContract::getContractInstruction, pageListDto.getContract_instruction())
				.like(!StringUtil.isEmpty(pageListDto.getCommentss()), ServiceContract::getCommentss, pageListDto.getCommentss())
				.like(!StringUtil.isEmpty(pageListDto.getAudit_state()), ServiceContract::getAuditState, pageListDto.getAudit_state())
				.eq(!StringUtil.isEmpty(pageListDto.getAuditor_id()), ServiceContract::getAuditorId, pageListDto.getAuditor_id())
				.ge(!StringUtil.isEmpty(pageListDto.getAudit_date_Start()), ServiceContract::getAuditDate, pageListDto.getAudit_date_Start())
				.le(!StringUtil.isEmpty(pageListDto.getAudit_date_End()), ServiceContract::getAuditDate, pageListDto.getAudit_date_End())
				.like(!StringUtil.isEmpty(pageListDto.getReject_reason()), ServiceContract::getRejectReason, pageListDto.getReject_reason())
				.like(!StringUtil.isEmpty(pageListDto.getService_name()), ServiceContract::getServiceName, pageListDto.getService_name())
				.like(!StringUtil.isEmpty(pageListDto.getContract_state()), ServiceContract::getContractState, pageListDto.getContract_state());
		return this.page(ConventPage.getPage(pageListDto), wrapper);
	}

	@Override
	public Integer addServiceContract(ServiceContract serviceContract) {
		boolean isSuccess = this.save(serviceContract);
		return isSuccess ? serviceContract.getId() : null;
	}

	@Override
	public boolean updateServiceContract(String id, ServiceContract serviceContract) {
		serviceContract.setId(Integer.valueOf(id));
		return this.updateById(serviceContract);
	}

	@Override
	public boolean delete(String ids) {
		List<String> idList = Func.toStrList(ids);
		return this.removeByIds(idList);
	}

}